package com.doit.demo01;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class demo01 {
    public static void main(String[] args) throws UnknownHostException {
        InetAddress local = InetAddress.getLocalHost();
        InetAddress remote = InetAddress.getByName("www.baidu.com");
        System.out.println("本机的IP地址:"+local.getHostAddress());
        System.out.println("百度的IP地址为:"+remote.getHostAddress());
        System.out.println("百度的主机名为:"+remote.getHostName());
    }
}
